package com.hassean.we.admin.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.hassean.we.admin.common.constant.CommonConstant;
import com.hassean.we.admin.common.util.Query;
import com.hassean.we.admin.common.util.R;
import com.hassean.we.admin.common.web.BaseController;
import com.hassean.we.admin.model.entity.TbRescueTeam;
import com.hassean.we.admin.service.TbRescueTeamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yajun
 * @since 2019-03-29
 */
@Api(description = "救援队接口")
@RestController
@RequestMapping("/tbRescueTeam")
public class TbRescueTeamController extends BaseController {
    @Autowired private TbRescueTeamService tbRescueTeamService;

    /**
    * 通过ID查询
    *
    * @param id ID
    * @return TbRescueTeam
    */
    @ApiOperation(value = "通过ID查询救援队" ,  notes="通过ID查询救援队")
    @GetMapping("/{id}")
    public R<TbRescueTeam> get(@PathVariable Long id) {
        return new R<>(tbRescueTeamService.selectById(id));
    }


    /**
    * 分页查询信息
    *
    * @param params 分页对象
    * @return 分页对象
    */
    @ApiOperation(value = "分页查询救援队" ,  notes="分页查询救援队")
    @RequestMapping("/page")
    public Page page(@RequestParam Map<String, Object> params) {
        params.put(CommonConstant.DEL_FLAG, CommonConstant.STATUS_NORMAL);
        return tbRescueTeamService.selectPage(new Query<>(params), new EntityWrapper<>());
    }

    /**
     * 添加
     * @param  tbRescueTeam  实体
     * @return success/false
     */
    @ApiOperation(value = "添加救援队" ,  notes="添加救援队")
    @PostMapping("/add")
    public R<Boolean> add(@RequestBody TbRescueTeam tbRescueTeam) {
        return new R<>(tbRescueTeamService.insert(tbRescueTeam));
    }

    /**
     * 删除
     * @param id ID
     * @return success/false
     */
    @ApiOperation(value = "删除救援队" ,  notes="删除救援队")
    @DeleteMapping("/{id}")
    public R<Boolean> delete(@PathVariable Long id) {
        TbRescueTeam tbRescueTeam = new TbRescueTeam();
        tbRescueTeam.setRescueTeamId(id);
        tbRescueTeam.setUpdateTime(new Date());
        tbRescueTeam.setDelFlag(CommonConstant.STATUS_DEL);
        return new R<>(tbRescueTeamService.updateById(tbRescueTeam));
    }

    /**
     * 编辑
     * @param  tbRescueTeam  实体
     * @return success/false
     */
    @ApiOperation(value = "编辑救援队" ,  notes="编辑救援队")
    @PutMapping
    public R<Boolean> edit(@RequestBody TbRescueTeam tbRescueTeam) {
        tbRescueTeam.setUpdateTime(new Date());

        return new R<>(tbRescueTeamService.updateById(tbRescueTeam));
    }
    /**
     * 获取所有救援队信息列表
     * @return success/false
     */
    @ApiOperation(value = "获取所有救援队信息列表" ,  notes="获取所有救援队信息列表")
    @RequestMapping("/tbRescueTeamList")
    public R<List> showTbRescueTeamList(@RequestParam Map<String, Object> params){
       List<Object>list = new ArrayList<>();
        TbRescueTeam tbRescueTeam = new TbRescueTeam ();

        EntityWrapper entity = new EntityWrapper<>();

        List<Object>selectList =   tbRescueTeamService.selectList(entity);

        //tbRescueTeamService.selectOne( new EntityWrapper<>(tbRescueTeam));

       return  new R<>(selectList);
    }
}
